<?php namespace Summer\Userhub\Updates;

use Schema;
use Winter\Storm\Database\Updates\Migration;

class UserAddLocationFields extends Migration
{
    public function up()
    {
        if (Schema::hasColumns('users', [
            'province_code',
            'city_code',
            'area_code',
            'street_addr'
        ])) {
            return;
        }

        Schema::table('users', function($table)
        {
            $table->string('province_code')->nullable();//省级编号
            $table->string('city_code')->nullable();//市级编号
            $table->string('area_code')->nullable();//区县编号
            $table->string('street_addr')->nullable();//街道地址
        });
    }

    public function down()
    {
        if (Schema::hasTable('users')) {
            Schema::table('users', function ($table) {
                $table->dropColumn([
                    'province_code',
                    'city_code',
                    'area_code',
                    'street_addr'
                ]);
            });
        }
    }
}
